/**
 * 09/dic/2011 - fabio.melillo@gmail.com
 */
package demo.unisannio;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

/**
 * @author fabio
 *
 */
public class DemoActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.demomain);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		boolean result =super.onCreateOptionsMenu(menu);
		MenuItem indirizzi=menu.add(Menu.NONE,1,1,"Indirizzi");
		MenuItem config=menu.add(Menu.NONE,2,2,"Configurazione");
		indirizzi.setIcon(android.R.drawable.ic_menu_agenda);
		config.setIcon(android.R.drawable.ic_menu_manage);
		return result;
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		switch (id) {
		case 1:
			if (BroadcastActivity.broadcaster!=null){
				Intent intent=new Intent(this, AddressListActivity.class);
				startActivity(intent);
				break;
			}else {
			AlertDialog.Builder builder = new AlertDialog.Builder(DemoActivity.this);
			builder.setMessage("Configura prima il Peer");
			builder.setCancelable(false);
			builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			               dialog.cancel();
			           }
			       });
			AlertDialog alert = builder.create();
			alert.show();
			}
			break;
			
		case 2:
			Intent intent=new Intent(this, ConfigActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
		return true;
	}
}
